Module.c("ComponentUtil");

var queryMode;



ComponentUtil.promptMsg=function(event,data){
	var eventType=event.type;
	var promptTitle='';
	var timeout = 1500;
	
	if (eventType == _EVENT_PROMPT_INFO){
		promptTitle = '提示';
		timeout = 1000;
	}else if(eventType == _EVENT_PROMPT_WARNING){
		promptTitle = '警告';
		timeout = 3000;
	}else if(eventType == _EVENT_PROMPT_ERROR){
		promptTitle = '错误';
		timeout = 0;
	}
	
	$.messager.show({
		title:promptTitle,
		msg:data,
		width:250,
		height:120,
		timeout:timeout
	});
	
}

ComponentUtil.localizePagination = function(paginationEle){
	$(paginationEle).pagination({
    		displayMsg:'显示从{from}至{to}   共{total}记录',
    		beforePageText:'第',
    		afterPageText:'页  共{pages}页'
	});
}

ComponentUtil.getErrorDesc=function(errorCode){
	
	if (errorCode=='errCodeHasRelativeRoles') return '删除失败:需要删除的权限正被某个角色引用,请先解除引用关系';
	if (errorCode=='errCodeHasRelativeAdmin') return '删除失败:需要删除的角色正被某个管理员引用,请先解除引用关系';
	
	
	return '未知错误(错误代码:'+errorCode+")";
}

ComponentUtil.showAdvancedQueryForm = function(){
	
	$('#simpleQueryForm').css("display","none");
	$('#advancedQueryForm').css("display","table");
	queryMode = _QUERY_MODE_ADVANCE;
	
}

ComponentUtil.hideAdvancedQueryForm = function(){
	
	$('#advancedQueryForm').css("display","none");
	$('#simpleQueryForm').css("display","table");
	queryMode = _QUERY_MODE_SIMPLE;
	
}

ComponentUtil.addPrivilegeAttr = function(elem,privilegeCode){
	$(elem).attr('PRIVILEGE_FILTER',privilegeCode);
}


ComponentUtil.privilegeFilter = function(){
	//adminPrivileges
	var elemNeedFilter = $('[PRIVILEGE_FILTER]');
	var aElement;

	for (var i=0;i<elemNeedFilter.length;i++){
		aElement = elemNeedFilter[i];
		if (!ComponentUtil.hasEnoughPrivilege($(aElement).attr('PRIVILEGE_FILTER'))){
			$(aElement).css("display","none");
		}
	}
	
}

ComponentUtil.hasEnoughPrivilege = function(privilegeCode){
	
	var aPrivilege;
	for(var i=0;i<adminPrivileges.length;i++){
		aPrivilege = adminPrivileges[i];
		if  (aPrivilege.code==privilegeCode){
			return true;
		}
	}
	return false;
}
